﻿using System;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

using xEngine.Input;

namespace xEngine.UI.Screens
{
    public abstract class LoadingScreen : Screen
    {
        #region Member Variables

        private int _current;

        #endregion

        #region Properties

        public float Progress { get { return Max > 0 ? ((float)Current / (float)Max) * 100 : 0; } }
        public int Max { get; set; }
        public int Current
        {
            get { return _current; }
            set
            {
                _current = value;
                if (Progress >= 100)
                    Hide();
            }
        }

        #endregion

        #region Constructors

        public LoadingScreen() : base(null)
        {
            Show();
        }

        #endregion

        #region Functions
        
        public string GetProgress()
        {
            string s = ((int)(Progress * 10) / 10.0f).ToString();
            if (!s.Contains("."))
                s += ".0";

            return s;
        }

        public void Show()
        {
            Max = 0;
            Current = 0;
            State = ScreenState.Normal;
            FadeTimeout = 0.0f;
            __alpha = 0.0f;
            Active = true;
        }
        public void Hide()
        {
            Current = Max = 0;
            __alpha = 1.0f;
            Active = false;
            State = ScreenState.Normal;
        }

        #endregion
    }
}
